package cn.ffcs.bpmpvc.dao.impl;


import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.ffcs.base.model.BaseEntity;
import cn.ffcs.bpm.model.Message;
import cn.ffcs.bpm.model.NextTep;
import cn.ffcs.bpmpvc.dao.MessageDao;


/**
 * 
 * 流程DAO实现<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">g.yedw</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:2010-4-12</td>
 * <td>修改人:g.yedw</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * 
 * @author g.yedw
 * @version $Id$
 */
public class MessageDaoImpl extends HibernateDaoSupport implements MessageDao {
	private JdbcTemplate jdbcTemplate;
	/**
	 * 获取共享资料实体类
	 * 
	 * @param b
	 * @return
	 */
	public String getEntityName() {
		return new NextTep().getClass().getName();
	}

	/**
	 * 按查询条件获取总数
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BaseEntity> findBy(Criterion cond) {
		final Criterion conds = cond;
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public List doInHibernate(Session session)
					throws HibernateException {
				Criteria criteria = session.createCriteria(getEntityName());
				criteria.add(conds);
				return criteria.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	public List<Message> findMessage(Message message) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer(
				"from Message t");
//		if (message.getMNumber() != null && !"".equals(message.getMNumber())) {
//			hql.append(" and m.mNumber='" + message.getMNumber() + "'");
//		}
		List<Message> list=getHibernateTemplate().find(hql.toString());
		return list;
		//return this.getSession().createQuery(hql.toString()).list();
	}

	public Message getMessage(Integer id) {
		// TODO Auto-generated method stub
		return (Message) getHibernateTemplate().get(Message.class, id);
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

}
